Environment setup
This document covers the essential setup required to start building on Orca’s SDK using the Whirlpools protocol. It includes wallet setup, RPC client configuration, airdropping tokens for testing, and the basics of interacting with the Solana ecosystem.
Prerequisites
- Typescript
- Rust
Before you start, ensure you have Node.js version 20 or higher installed on your machine. Download it from the official website: https://nodejs.org/.
Before you start, ensure you have Rust installed. To ensure compatibility with the Solana SDK v1.18, we recommend using rustc 1.78.0
.
1. Initialize a new project
- Typescript
- Rust
Create a new project directory:
mkdir <project-name>
cd <project-name>
Initialize a new Node.js project:
npm init -y
Install the necessary packages:
npm install typescript @orca-so/whirlpools @solana/web3.js@2
Initialize the project as a TypeScript project:
npx tsc --init
Initialize a new Rust project:
cargo new <project-name>
Add the necessary dependencies to your project:
cargo add orca_whirlpools solana-sdk@1.18 solana-client@1.18 tokio serde_json
2. Wallet Management
You can generate a file system wallet using the Solana CLI and load it in your program.
- Typescript
- Rust
import { createKeyPairSignerFromBytes } from '@solana/web3.js';
import fs from 'fs';
const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
const wallet = await createKeyPairSignerFromBytes(keyPairBytes);
use solana_sdk::signer::keypair::Keypair;
use solana_sdk::signature::Signer;
use std::fs;
fn main() {
let wallet_string = fs::read_to_string("path/to/wallet.json").unwrap();
let keypair_bytes: Vec<u8> = serde_json::from_str(&wallet_string).unwrap();
let wallet = Keypair::from_bytes(&keypair_bytes).unwrap();
}
⚠️ Important: Never share your private key publicly.
3. Configure the Whirlpools SDK for Your Network
Orca's Whirlpools SDK supports several networks: Solana Mainnet, Solana Devnet, Eclipse Mainnet, and Eclipse Testnet. To select a network, use the setWhirlpoolsConfig
function. This ensures compatibility with the network you’re deploying on.
Example: Setting the SDK Configuration to Solana Devnet
- Typescript
- Rust
import { setWhirlpoolsConfig } from '@orca-so/whirlpools';
await setWhirlpoolsConfig('solanaDevnet');
use orca_whirlpools::{WhirlpoolsConfigInput, set_whirlpools_config_address};
fn main() {
set_whirlpools_config_address(WhirlpoolsConfigInput::SolanaDevnet).unwrap();
// Rest of the code
}
Available networks are:
- solanaMainnet
- solanaDevnet
- eclipseMainnet
- eclipseTestnet
ℹ️ The
setWhirlpoolsConfig
function accepts either one of Orca's default network keys or a customAddress
. This allows you to specify a WhirlpoolsConfig account of your choice, including configurations not owned by Orca. To learn more about WhirlpoolsConfig read our Account Architecture documentation.
4. Airdrop SOL to Your Wallet
Once your wallet is created, you will need some SOL to pay for transactions. You can request an airdrop of SOL from the network, but this is only available on Solana Devnet and Ecipse Testnet.
- Typescript
- Rust
import { generateKeyPair, createSolanaRpc, devnet, getAddressFromPublicKey } from '@solana/web3.js';
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
const wallet = await generateKeyPairSigner();
devnetRpc.requestAirdrop(
wallet.address,
lamports(1000000000n)
).send()
use solana_client::rpc_client::RpcClient;
use solana_sdk::signature::Signer;
fn main() {
// Rest of the code
let rpc_client = RpcClient::new("https://api.devnet.solana.com");
match rpc_client.request_airdrop(&wallet.pubkey(), 1_000_000_000) {
Ok(signature) => println!("Airdrop successful. Transactoin signature: {:?}", signature),
Err(e) => println!("Error: {:?}", e),
}
}
5. Set the default funder for Transactions
After funding your wallet, you can set the wallet as the FUNDER for future transactions within the SDK. The funder is the account that will cover the transaction costs for initializing pools, providing liquidity, etc.
- Typescript
- Rust
import { setDefaultFunder } from '@orca-so/whirlpools';
setDefaultFunder(wallet);
use orca_whirlpools::{set_funder};
use solana_sdk::signature::Signer;
fn main() {
// Rest of the code
set_funder(wallet.pubkey()).unwrap();
}
Next steps
Once you’ve completed the setup, you can move on to building more complex functionalities using the Orca SDK, such as creating and managing pools, providing liquidity, etc. Refer to individual function documentation to use this wallet setup in action.